import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

const routerPush = Router.prototype.push
const originalReplace = Router.prototype.replace

Router.prototype.push = function push(location, onResolve, onReject) {
  if (onResolve || onReject) return routerPush.call(this, location, onResolve, onReject)

  return routerPush.call(this, location).catch((error) => {
    console.log(error)
  })
}

Router.prototype.replace = function push(location, onResolve, onReject) {
  if (onResolve || onReject) return originalReplace.call(this, location, onResolve, onReject)
  return originalReplace.call(this, location).catch((err) => {
    console.log(err)
  })
}

let routes = [
  {
    path: '/',
    redirect: { name: 'login' }
  },
  {
    path: '/login',
    name: 'login',
    component: () => import('@/views/login')
  },
  {
    path: '/customerService',
    meta: {
      title: '客服系统'
    },
    component: () => import('@/views/menu/index.vue'),
    children: [
      {
        path: 'customerseSrviceModuleManagement',
        name: 'customerseSrviceModuleManagement',
        component: () => import('@/views/customerseSrviceModuleManagement/index.vue'),
        meta: {
          title: '客服管理模块'
        }
      },
      {
        path: 'customerseSrviceModuleManagement/detail',
        name: 'customerseSrviceModuleManagementDetail',
        component: () => import('@/views/customerseSrviceModuleManagement/detail.vue'),
        meta: {
          title: '客服管理模块详情'
        }
      },

      {
        path: 'orderManagement',
        name: 'orderManagement',
        component: () => import('@/views/orderManagement/index.vue'),
        meta: {
          title: '工单管理'
        }
      },
      {
        path: 'channelEntrance',
        name: 'channelEntrance',
        component: () => import('@/views/channelEntrance/index.vue'),
        meta: {
          title: '渠道入口'
        }
      },
      {
        path: 'problemFeedManage',
        name: 'problemFeedManage',
        component: () => import('@/views/problemFeedManage/index.vue'),
        meta: {
          title: '问题反馈管理'
        }
      },
      {
        path: 'templateManage',
        name: 'templateManage',
        component: () => import('@/views/templateManage/index.vue'),
        meta: {
          title: '模板管理'
        }
      },
      {
        path: 'templateManage/form',
        name: 'templateManageForm',
        component: () => import('@/views/templateManage/form.vue'),
        meta: {
          title: '模板管理详情'
        }
      },
      {
        path: 'templateManage/batchAdd',
        name: 'templateManagebatchAdd',
        component: () => import('@/views/templateManage/batchAdd.vue'),
        meta: {
          title: '批量导入'
        }
      },
      {
        path: 'questionManage',
        name: 'questionManage',
        component: () => import('@/views/questionManage/index.vue'),
        meta: {
          title: '问题管理'
        }
      },
      {
        path: 'questionManage/commonForm',
        name: 'questionManageCommonForm',
        component: () => import('@/views/questionManage/commonForm.vue'),
        meta: {
          title: '常见问题新增'
        }
      },
      {
        path: 'questionManage/complaintForm',
        name: 'questionManageComplaintForm',
        component: () => import('@/views/questionManage/complaintForm.vue'),
        meta: {
          title: '订单投诉问题新增'
        }
      },
      {
        path: 'questionManage/subproblemList',
        name: 'subproblemList',
        component: () => import('@/views/questionManage/subproblemList.vue'),
        meta: {
          title: '子问题'
        }
      },
      {
        path: 'noResultList',
        name: 'noResultList',
        component: () => import('@/views/noResultList/index.vue'),
        meta: {
          title: '无解问题列表'
        }
      },
      {
        path: 'downloadManage',
        name: 'downloadManage',
        component: () => import('@/views/downloadManage/index.vue'),
        meta: {
          title: '下载管理'
        }
      }
    ]
  }
]

export default routes
